


import request from "@/utils/request";

export interface reqCategoryItemType {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
  category3Id?: number;
}

export type reqCategoryType = reqCategoryItemType[];

//1.请求一级分类列表
export const requestCategory1 = () => {
  return request.get<any, reqCategoryType>(`/admin/product/getCategory1`);
};

//2.请求二级分类列表
export const requestCategory2 = (category1Id: number) => {
  return request.get<any, reqCategoryType>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

//3.请求三级分类列表
export const requestCategory3 = (category2Id: number) => {
  return request.get<any, reqCategoryType>(
    `/admin/product/getCategory3/${category2Id}`
  );
};

/* 
  以下是添加属性的类型值
*/
//某个属性内属性值列表的类型
export interface valueType {
  id?: number | undefined,
  valueName: string,
  attrId: number | undefined,
  isEdit?: boolean;
}

//某个属性的类型
export interface attrubuteType {
  id?: number | undefined,
  attrName: string,
  categoryId: number,
  categoryLevel: number,
  attrIdAttrValueId?: string;
  attrValueList: valueType[]
}

//属性列表的类型
export type attrListType = attrubuteType[]

//4.获取当前三级分类的属性
export const getAttrInfoList = (category1Id: number, category2Id: number, category3Id: number) => {
  return request.get<any, attrListType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}
//5.删除当前三级分类的属性
export const deleteAttrInfoList = (attrId: number) => {
  return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`)
}

//6.新增或修改当前三级分类的属性
export const addOrchangeAttrInfoList = (data: attrubuteType) => {
  return request.post<any, null>(`/admin/product/saveAttrInfo`, data)
}